class WechatConfirmUI extends UIBase{
    constructor(data)
    {
        super('WeCahtConfirmView', data);
    }

    public init()
    {
        let self = this;
        let call = function()
        {
            self.sendRoleInfo();
        }
        WeChatgGameManager.instance().showUserInfoButton(call, self);
    }

    public addEvent()
    {

    }

    public removeEvent()
    {

    }

    public sendRoleInfo()
    {
        let userInfo = WeChatgGameManager.instance().userInfo;
        if(userInfo)
        {
            let nick_name = "阿佳虎啊";
            let avatar_url = "https://wx.qlogo.cn/mmopen/vi_32/XkkpCONgGIC2oA3cVRYkF0OyHonYs0M4DySGCtUCh8G5d3n5mMnl5PIB0hZF6pvU0bMvlgZpNCGw8LYDhicgdrQ/132";
            if(userInfo)
            {   
                nick_name = userInfo['nickName'] != undefined ? userInfo['nickName']: nick_name;
                avatar_url = userInfo['avatarUrl'] != undefined ? userInfo['avatarUrl']: avatar_url;
                
            }
            let user = {
                nick_name:nick_name,
                avatar:avatar_url,
                version:GameConst.version
            }
            let self = this;
            let type = this.data.type;
            HttpManager.instance().sendPost(GameConst.httpUrl + 'warrioruser/update_user_info', StringUtil.jsonToHttpPostString(user), (e)=>{
                let data = JSON.parse(e);
                if(data.msg == 'ok')
                {   
                    WeChatgGameManager.instance().hideUserInfoButton();
                    RoleCache.instance().nick_name = nick_name;
                    RoleCache.instance().avatar_url = avatar_url;
                    if(type == confirmType.openWorldRank)
                    {
                        let data = {
                            isPop:true,
                            effect:2
                        }
                        UIManager.instance().openUILogic(WorldRankUI, data);
                    }
                    else if(type == confirmType.enterEndLessGame)
                    {
                        let data = {
                            isPop:true,
                            effect:1
                        }
                        UIManager.instance().openUILogic(EndLessSamllRankUI,data);
                    }
                    self.remove();
                }
            })
        }   
    }

    public clear()
    {
        super.clear();
    }
}

enum confirmType{
    default,
    enterEndLessGame,
    openWorldRank,
    max
}